/*
 * @Descripttion:
 * @version:
 * @Author: lily
 * @Date: 2021-04-07 16:27:18
 * @LastEditors: lily
 * @LastEditTime: 2021-04-07 16:45:36
 */
/**
 * @param {number[]} numbers
 * @return {number}
 */

//  思路： 二分法
//  比较中间的数和最右边数的关系来缩小比较的范围

//  复杂度：O(logn) O(1)

var minArray = function (numbers) {
    let right = numbers.length - 1, left = 0
    while (left < right) {
        let mid = Math.floor((right + left) / 2)
        if (numbers[mid] > numbers[right]) {
            left = mid + 1
        } else if (numbers[mid] < numbers[right]) {
            right = mid
        } else {
            right--
        }
    }
    return numbers[left]
};

console.log(minArray([3, 4, 5, 1, 2]));